var element;
var userTableInfo;

var initColumns=[
    {
        // radio: true, // 单选
        checkbox: true,
        width: 50
    },
    {title: '用户ID', field: 'userId', align: 'center', valign: 'middle',width:'50px'},
    {title: '登录名称', field: 'loginName', align: 'center', valign: 'middle', sortable: true},
    {title: '用户名称', field: 'userName', align: 'center', valign: 'middle', sortable: true},
    {title: '用户类型', field: 'userType', align: 'center', valign: 'middle', sortable: true},
    {title: '部门', field: 'deptId', align: 'center', valign: 'middle', sortable: true},
    {title: '手机', field: 'phonenumber', align: 'center', valign: 'middle', sortable: true},
    {title: '性别', field: 'sex', align: 'center', valign: 'middle', sortable: true},
    {title: '用户状态', field: 'status', align: 'center', valign: 'middle', sortable: true},
    {title: '创建时间', field: 'createTime', align: 'center', valign: 'middle', sortable: true,
        //获取日期列的值进行转换
        formatter: function (value, row, index) {
            return changeDateFormat(value)
        }},
    {title: '登陆IP', field: 'loginIp', align: 'center', valign: 'middle', sortable: true},
    {title: '创建者', field: 'createBy', align: 'center', valign: 'middle', sortable: true},
    {title: '操作', field: 'email', align: 'center', valign: 'middle', sortable: true}
 ];




$(function() {


    layui.use(['element', 'layer', 'laydate','table'], function(){
         element = layui.element;
        usertable = layui.table;
        var layer = layui.layer;
        var laydate = layui.laydate;
        //监听折叠
        element.init();
    });

    userTableInfo = new BSTable("user_table", "/user/queryUserByPage", initColumns);
   // table.setPaginationType("client");
    userTableInfo.init();


});

//转换日期格式(时间戳转换为datetime格式)
function changeDateFormat(cellval) {
    var dateVal = cellval + "";
    if (cellval != null) {
        var date = new Date(+new Date(cellval)+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'') ;
        /*var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();

        var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
        var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();*/

        return date;
    }
}


function searchUserInfo() {
    var searchUserName= $("#searchUserName").val();

    var param = {
        query:{
            userName:searchUserName
        }
    };
    userTableInfo.refresh(param);

}